<template>
  <div class="bodys">
    <div class="text">
      个人信息设置
    </div>
    <el-card>
      <div class="header">
        <div class="header-box1">
          <div>
            头像 ：
          </div>
          <upload-img v-model="user.avatar" />
        </div>
        <div class="header-box2">
          <el-form ref="ruleForm" :model="user" :rules="rules" label-width="100px" class="demo-ruleForm">
            <el-form-item label="姓名：" prop="name">
              <el-input v-model="user.name" />
            </el-form-item>
            <el-form-item label="电话：" prop="name">
              <el-input v-model="user.mobile" />
            </el-form-item>
            <el-form-item label="性别：" prop="name">
              <el-radio-group v-model="user.gender">
                <el-radio label="男" />
                <el-radio label="女" />
              </el-radio-group>
            </el-form-item>
            <div class="btns">
              <el-button type="primary" @click="editList">确认修改</el-button>
            </div>
            <div class="userBtn">
              <el-button type="info">修改账号</el-button>
              <el-button type="danger">修改密码</el-button>
            </div>
          </el-form>
        </div>
      </div>

    </el-card>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { editUserApi } from '@/api/user'
import uploadImg from '../UnderlyingData/components/uploadImg.vue'
export default {
  components: { uploadImg },
  data() {
    return {
      // 用户头像
      user: {
        avatar: '',
        mobile: null,
        name: '',
        gender: ''
      },
      rules: {
        name: [
          { required: true, message: '请输入', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {
    ...mapGetters([
      'userInfo'
    ])
  },
  created() {
    console.log(this.userInfo)
    if (this.userInfo.avatar === '') {
      this.user.avatar = ''
    } else {
      this.user.avatar = `http://forest.kmdsoft.net/storage/${this.userInfo.avatar}`
    }

    this.user.mobile = this.userInfo.mobile
    this.user.name = this.userInfo.name
    this.user.gender = this.userInfo.gender
  },
  methods: {
    async editList() {
      await editUserApi(this.user)
      this.$message.success('修改成功！请重新登录。')
      console.log(this.user)
    }
  }
}
</script>

<style lang="scss" scoped>
.text {
  height: 60px;
  font-size: 20px;
  margin-left: 10px;
  color: #888;
  margin-right: 20px;
  font-weight: 500;
  font-size: 22px;
  line-height: 60px;
  margin-left: 20px;
}
.bodys{
  background-color: #eeefee;
  height: 100%;
}
.el-card{
  height: 400px;
}
.isImg{
  width: 150px;
  height: 150px;
  border-radius: 150px;
}

.img-txt{
  margin-left: 50%;
  div{
    float: left;
  }

}
.userBtn{
position: absolute;
right: 20px;
bottom: 20px;
}
.gengxin{
  margin-left: 21%;
}
.el-card{
  height: 100%;
}
.userBtn{
  float: right;
}
.btns{
  margin-left: 80%;
}
.header{
  // position: relative;
  display: flex;
  justify-content: space-evenly;
  .header-box1{
    // position: absolute;
    // right: 0;
    width: 50%;
    // float: left;
    padding-left: 25%;
    display: flex;
    justify-content: space-around;
  }
  .header-box2{
    float: right;
    width: 50%;
    margin-right: 25%;
  }
}
.el-card{
  height: 350px;
}
</style>
